package model.entity;

import java.util.Iterator;
import java.util.List;

import model.ability.PassiveSkill;
import model.core.Logger;
import model.map.AvatarStateObserver;
import model.map.MapPoint;
import model.mediators.InteractiveMediator;
import model.mediators.InventoryMediator;
import model.stats.StatsContainer;

/**
 * 
 * @author srhinson
 *moved the levelup method into this class. 
 * 	 getSkillList should make levelup universal according to new design.
 *   can still overwrite if not.
 *notifyOfRange was change per zacks request
 */
public abstract class Avatar extends Entity {
	AvatarStateObserver observer;
	InventoryMediator inventoryMediator;
	
	public Avatar(String name, String occName, MapPoint origin, StatsContainer stats,
			MovementType movement, int obs, int bar, int bind, DirectionalGraphicSet graphics){
		super(name, occName, origin, stats,
			movement, obs, bar, bind, graphics);
	}
	
	public Avatar(){
		super();
	}
	
	public void setStateObserver(AvatarStateObserver ob){
		this.observer = ob;
	}
	
	public void setInventoryMediator(InventoryMediator mediator){
		this.inventoryMediator=mediator;
	}
	
	public void interactWith(List<Entity> entityList) {
		Iterator<Entity> iter = entityList.iterator();
		while (iter.hasNext()) {
			InteractiveMediator mediator= new InteractiveMediator(this, iter.next());
		}
	}

	public void setLocation(MapPoint newLocation) {
		observer.updateState();
		super.setLocation(newLocation);
		observer.updateState();
		
	}
	
	public void notifyOfRange(){
		observer.updateState();
	}
	
	public void notifyOfMove(){
		observer.updateState()	;
	}
	
	public void notifyOfDeath(Entity foe){
		Logger.getInstance().writeToLogger(foe.getName()+" has perished from this mortal coil");
	}
	
	public void makeHostile(Entity caster){
		Logger.getInstance().writeToLogger("you were attacked by "+caster.getName());
	}

    public void affectFavorability(int mag, int dur) {
            int rand=(int) (Math.random()*20);
            if(mag<rand)return;
            else this.diasbleAttack(dur);
    }
    
    public void levelup(){
    	Iterator<PassiveSkill> i = this.getSkillList().iterator();
    	while(i.hasNext()){
    		i.next().levelUp();
    	}
    }
}
